﻿using KinonekoSoftware.CodariaDB.Documents.Index;

namespace KinonekoSoftware.CodariaDB.Documents.DataParts.Schools
{
    public sealed class SeatSlot : ObservableObject
    {
        private string _name;

        public static byte GetIndex(int column, int row)
        {
            return (byte)(((row) & 0xf0) << 4 | column);
        }

        [BsonIgnore]
        [JsonIgnore]
        public int Column
        {
            get => (Index & 0x0f);
            set
            {
                var byteValue = (byte)Math.Clamp(value, 0, 16);
                Index = (byte)((Index & 0xf0) | (byteValue & 0x0f));
            }
        }

        [BsonIgnore]
        [JsonIgnore]
        public int Row
        {
            get => (Index & 0xf0) >> 4;
            set
            {
                // 00010000
                var byteValue = (byte)Math.Clamp(value, 0, 16);
                Index = (byte)(((byteValue << 4) & 0xf0) | (Index & 0x0f));
            }
        }

        public byte   Index       { get; set; }
        public string CharacterID { get; set; }

        [BsonIgnore]
        public InstanceCache Character { get; set; }


        public string Name
        {
            get => _name;
            set => SetValue(ref _name, value);
        }
    }
}